package as.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import as.entity.AttendanceRecord;
import as.entity.Student;
import as.exception.ValidateException;
import as.service.AttendanceRecordService;
import as.util.Page;

public class AttendanceRecordAction extends BaseAction {
	private Date startTime;
	private Date endTime;
	private long studentId;
	private long courseId;
	private int pageNo;
	private int maxPageNo;
	private List<Student> studentList;

	private List<AttendanceRecord> list;
	private AttendanceRecordService attendanceRecordService;
	private  String url;

	

	public String viewAttendanceDetail() {
		pageNo = pageNo == 0 ? 1 : pageNo;
		try {
			List<AttendanceRecord> allRecords = attendanceRecordService.list(
					courseId, studentId, startTime, endTime);
			list = new ArrayList<AttendanceRecord>();
			maxPageNo = Page.page(allRecords, 30, pageNo, list);
		} catch (ValidateException e) {

			addError("viewAttendanceDetail", e.getMessage());
			return ERROR;
		}

		return SUCCESS;

	}
	public String viewNowAttendance(){
		if (courseId<1){
			url=ServletActionContext.getRequest().getRequestURL().toString();
			if(url.indexOf("?")<0)
				url=url+"?";
		return INPUT;}
		studentList=attendanceRecordService.nowAttendance(courseId);
		return SUCCESS;
	}
	

	public void setMaxPageNo(int maxPageNo) {
		this.maxPageNo = maxPageNo;
	}

	public List<AttendanceRecord> getList() {
		return list;
	}

	public void setList(List<AttendanceRecord> list) {
		this.list = list;
	}

	public void setAttendanceRecordService(
			AttendanceRecordService attendanceRecordService) {
		this.attendanceRecordService = attendanceRecordService;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public long getStudentId() {
		return studentId;
	}

	public void setStudentId(long studentId) {
		this.studentId = studentId;
	}

	public long getCourseId() {
		return courseId;
	}

	public void setCourseId(long courseId) {
		this.courseId = courseId;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getMaxPageNo() {
		return maxPageNo;
	}

	public List<Student> getStudentList() {
		return studentList;
	}

	public void setStudentList(List<Student> studentList) {
		this.studentList = studentList;
	}
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
}
